import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace RoomEnvironmentApi {
  /** SPA房间环境监控信息 */
  export interface RoomEnvironment {
    id: number; // 主键ID
    roomId?: number; // 房间ID
    monitorTime?: string | Dayjs; // 监控时间
    temperature: number; // 温度(°C)
    humidity: number; // 湿度(%)
    airQuality: string; // 空气质量
    noiseLevel: number; // 噪音水平(dB)
    lightingLevel: number; // 光照水平(lux)
    waterTemperature: number; // 水温(°C)
    waterQuality: string; // 水质
    environmentMetrics: string; // 环境指标JSON
    scope: string; // 权限范围
    scoperef: string; // 权限引用
  }
}

/** 查询SPA房间环境监控分页 */
export function getRoomEnvironmentPage(params: PageParam) {
  return requestClient.get<PageResult<RoomEnvironmentApi.RoomEnvironment>>(
    '/spa/room-environment/page',
    { params },
  );
}

/** 查询SPA房间环境监控详情 */
export function getRoomEnvironment(id: number) {
  return requestClient.get<RoomEnvironmentApi.RoomEnvironment>(
    `/spa/room-environment/get?id=${id}`,
  );
}

/** 新增SPA房间环境监控 */
export function createRoomEnvironment(
  data: RoomEnvironmentApi.RoomEnvironment,
) {
  return requestClient.post('/spa/room-environment/create', data);
}

/** 修改SPA房间环境监控 */
export function updateRoomEnvironment(
  data: RoomEnvironmentApi.RoomEnvironment,
) {
  return requestClient.put('/spa/room-environment/update', data);
}

/** 删除SPA房间环境监控 */
export function deleteRoomEnvironment(id: number) {
  return requestClient.delete(`/spa/room-environment/delete?id=${id}`);
}

/** 导出SPA房间环境监控 */
export function exportRoomEnvironment(params: any) {
  return requestClient.download('/spa/room-environment/export-excel', {
    params,
  });
}
